package com.easylinkin.linkappapi.quality.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionInfoDto;
import com.easylinkin.linkappapi.quality.dto.QualityQuestionStatisticsQueryDTO;
import com.easylinkin.linkappapi.quality.entity.QualityQuestionInfo;
import com.easylinkin.linkappapi.quality.entity.vo.QualityQuestionInfoVo;
import com.easylinkin.linkappapi.quality.service.QualityQuestionInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * QualityQuestionInfo表控制层
 *
 * @author zhengwen
 * @date 2022/08/16
 */
@RestController
@RequestMapping("appQualityQuestionInfo")
@Api(tags = "质量问题管理")
public class QualityQuestionInfoController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private QualityQuestionInfoService appQualityQuestionInfoService;

    /**
     * 分页查询所有数据
     *
     * @param requestModel 查询分页对象
     * @return 所有数据
     */
    @PostMapping("getPage")
    @ApiOperation("查询分页")
    public RestMessage selectPage(@RequestBody RequestModel<QualityQuestionInfo> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<QualityQuestionInfo> record = appQualityQuestionInfoService.selectPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @ApiOperation("查询单条")
    public RestMessage selectDtoOne(@PathVariable Long id) {
        return this.appQualityQuestionInfoService.selectDtoOne(id);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/openapi/{id}")
    @ApiOperation("查询单条")
    public RestMessage selectDtoOneFromEnterprise(@PathVariable Long id) {
        return this.appQualityQuestionInfoService.selectDtoOneFromEnterprise(id);
    }

    /**
     * 新增数据
     *
     * @param appQualityQuestionInfo 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation("新增")
    public RestMessage insert(@RequestBody QualityQuestionInfo appQualityQuestionInfo) {
        return RestBuilders.successBuilder().success((this.appQualityQuestionInfoService.saveOne(appQualityQuestionInfo))).build();
    }

    /**
     * 修改数据
     *
     * @param appQualityQuestionInfo 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation("修改单条")
    public RestMessage update(@RequestBody QualityQuestionInfo appQualityQuestionInfo) {
        return RestBuilders.successBuilder().success(this.appQualityQuestionInfoService.updateOne(appQualityQuestionInfo)).build();
    }

  /**
   * 修改整改人
   *
   * @param hiddenDanger 实体对象
   * @return 修改结果
   */
  @PostMapping("modifyRectifyUser")
  @ApiOperation("修改整改人")
  public RestMessage modifyRectifyUser(@RequestBody QualityQuestionInfo appQualityQuestionInfo) {
    return RestBuilders.successBuilder()
        .success(this.appQualityQuestionInfoService.modifyRectifyUser(appQualityQuestionInfo))
        .build();
  }

  /**
   * 修改复查人
   *
   * @param hiddenDanger 实体对象
   * @return 修改结果
   */
  @PostMapping("modifyCheckUser")
  @ApiOperation("修改整改人")
  public RestMessage modifyCheckUser(@RequestBody QualityQuestionInfo appQualityQuestionInfo) {
    return RestBuilders.successBuilder()
        .success(this.appQualityQuestionInfoService.modifyCheckUser(appQualityQuestionInfo))
        .build();
  }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    @ApiOperation("批量删除")
    public RestMessage delete(@RequestParam("idList") List<Long> idList) {
        return RestBuilders.successBuilder().success(this.appQualityQuestionInfoService.deleteByIds(idList)).build();
    }

    @PostMapping("export")
    @ApiOperation("导出")
    public void export(@RequestBody QualityQuestionInfo appQualityQuestionInfo, HttpServletRequest request, HttpServletResponse response) {
        appQualityQuestionInfoService.export(appQualityQuestionInfo, request, response);
    }

    /**
     * 问题保存
     *
     * @param qualityQuestionInfoVo 实体对象
     * @return 新增结果
     */
    @PostMapping("/saveQuestion")
    @ApiOperation("问题保存")
    public RestMessage saveQuestion(@RequestBody QualityQuestionInfoVo qualityQuestionInfoVo) {
        return appQualityQuestionInfoService.saveQuestion(qualityQuestionInfoVo);
    }

    /**
     * 分页查询所有数据
     *
     * @param requestModel 查询分页对象
     * @return 所有数据
     */
    @PostMapping("/selectDtoPage")
    @ApiOperation("问题列表")
    public RestMessage selectDtoPage(@RequestBody RequestModel<QualityQuestionInfoVo> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<QualityQuestionInfoDto> record = appQualityQuestionInfoService.selectDtoPage(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 分页查询所有数据
     * @author tong jie
     * @param requestModel 查询分页对象
     * @return 所有数据
     */
    @PostMapping("/openapi/selectDtoPageFromEnterprise")
    @ApiOperation("问题列表")
    public RestMessage selectDtoPageFromEnterprise(@RequestBody RequestModel<QualityQuestionInfoVo> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<QualityQuestionInfoDto> record = appQualityQuestionInfoService.selectDtoPageFromEnterprise(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder(record).build();
    }

    /**
     * 获取tab头上的数量
     * @param questionInfoVo 问题入参
     * @return 统一出参
     */
    @PostMapping("/getTabCountNum")
    @ApiOperation("问题Tab头数量获取")
    public RestMessage getTabCountNum(@RequestBody QualityQuestionInfoVo questionInfoVo) {
        return appQualityQuestionInfoService.getTabCountNum(questionInfoVo);
    }


    @PostMapping("/countQualityQuestionByType")
    @ApiOperation("质量问题分析统计")
    public RestMessage countQualityQuestionByType(@RequestBody RequestModel<QualityQuestionStatisticsQueryDTO> requestModel) {
        return appQualityQuestionInfoService.countQualityQuestionByType(requestModel.getPage(), requestModel.getCustomQueryParams());
    }

    @PostMapping("exportCountQualityQuestionByType")
    @ApiOperation("导出质量问题分析统计")
    public void exportCountQualityQuestionByType(@RequestBody QualityQuestionStatisticsQueryDTO queryDTO, HttpServletRequest request, HttpServletResponse response) {
        appQualityQuestionInfoService.exportCountQualityQuestionByType(queryDTO, request, response);
    }


}

